package com.tanhua.server.interceptor;

import com.tanhua.model.domain.User;

/**
 * 工具类,向ThreadLocal存储数据获取数据
 */
public class UserHolder {
    private static ThreadLocal<User> tl = new ThreadLocal<>();

    //将用户对象存入ThreadLocal
    public static void set(User user){
        tl.set(user);
    }

    //从当前线程获取对象
    public static User get(){
       return tl.get();
    }

    //获取当前用户对象id
    public static Long getUserId(){
        return tl.get().getId();
    }

    //从当线程,获取用户对象手机号
    public static String getMobile(){
        return tl.get().getMobile();
    }

    //清空
    public static void remove(){
        tl.remove();
    }
}
